package com.vains.controller;

import com.vains.entity.OauthUser;
import com.vains.utils.SecurityContextUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author vains
 * @since 2020-07-03
 */
@RestController
@AllArgsConstructor
@Api(tags = "用户相关接口")
@RequestMapping("/oauthUser")
public class OauthUserController {

    private final ResourceServerTokenServices resourceServerTokenServices;

    @GetMapping("/user")
    @ApiOperation(value = "根据token获取当前用户信息", notes = "token可以放在请求头中或请求参数中")
    public OauthUser user(){
        return SecurityContextUtils.getCurrentUser(resourceServerTokenServices);
    }

}